#include "ResourcePath.h"

#include "ResPathImage.h"
#include "ResPathScript.h"
#include "ResPathSound.h"
#include "ResPathSprite.h"
#include "ResPathFont.h"
#include "ResPathVideo.h"

#include "../KmyAlgorithm.h"

ResourcePath::ResourcePath()
{
}

ResourcePath* ResourcePath::createResPath(string &line){
    /** 资源名 资源类型 资源路径（相对路径 …………*/
    vector<string>* strs = split(line, " ");
    if (strs->size()<3){
        return NULL;
    }
    string name = strs->at(0);
    string type = strs->at(1);
    string path = strs->at(2);
    string path2;
    string path3;
    string path4;
    if (strs->size()>3){
        path2 = strs->at(3);
    }
    if (strs->size()>4){
        path3 = strs->at(4);
    }
    if (strs->size()>5){
        path4 = strs->at(5);
    }

	//delete strs;
	strs->clear();
    delete strs;
    string_toupper(type);
    if (type == "IMAGE"){
        ResPathImage *rp = new ResPathImage(name, path, path2);
        return (ResourcePath*)rp;
    }else if (type == "SCRIPT"){
        ResPathScript *rp = new ResPathScript(name, path, path2, path3);
        return (ResourcePath*)rp;
    }else if (type == "SOUND"){
        ResPathSound *rp = new ResPathSound(name, path);
        return (ResourcePath*)rp;
    }else if (type == "SPRITE"){
        ResPathSprite *rp = new ResPathSprite(name, path);
        return (ResourcePath*)rp;
    }else if (type == "FONT"){
        ResPathFont *rp = new ResPathFont(name, path, path2, path3, path4);
        return (ResourcePath*)rp;
    }else if (type == "VIDEO"){
        ResPathVideo *rp = new ResPathVideo(name, path);
        return (ResourcePath*)rp;
    }
    return NULL;
}
